#!/bin/sh

CXX=${CXX:-g++}

if [ "$1" = "clean" ]
then
	( cd `dirname $0`; rm -f *.cxx *.so *.o mlt.i ../.python mlt.py* )
	exit 0
fi

path=`which python 2> /dev/null`

if [ $? = 0 ]
then
	# Change this as needed
	export PYTHON_INCLUDE=`python -c "import sys;print \"%s/include/python%d.%d\"%(sys.prefix,sys.version_info[0],sys.version_info[1])"`

	[ ! -d "$PYTHON_INCLUDE" ] && echo python development missing && exit 1

	ln -sf ../mlt.i

	# Invoke swig
	swig -c++ -I../../mlt++ -I../.. -python mlt.i || exit $?

	# Compile the wrapper
	${CXX} -fPIC -D_GNU_SOURCE ${CXXFLAGS} -c -I../.. -I$PYTHON_INCLUDE mlt_wrap.cxx || exit $?

	# Create the module
	${CXX} ${CXXFLAGS} -shared mlt_wrap.o -L../../mlt++ -lmlt++ -L../../framework -lmlt $(python-config --ldflags) -o _mlt.so || exit $?
else
	echo Python not installed.
	exit 1
fi
